package services

import (
	"regexp"
	"strings"
)

type ChatRule struct {
}

// 前19个字符,日期时间
func (r *ChatRule) GetActionTime(str string) string {
	return str[:19]
}

// userid,username,streamid,
func (r *ChatRule) GetPlayerInfo(str string) (string, string, string) {
	reg := regexp.MustCompile(`'([^']*)'`)
	strslice := reg.FindStringSubmatch(str)
	if len(strslice) == 0 {
		return "", "", ""
	}
	playerTxt := strslice[1]
	//冒号分割strings.Split(strslice[1], ":")
	splitSlice := strings.Split(playerTxt, ":")
	if len(splitSlice) < 2 {
		return "", "", ""
	}
	//处理玩家id
	playerStreamId := splitSlice[0]
	reg1 := regexp.MustCompile(`\((.*?)\)`)
	playnameTxt := reg1.FindStringSubmatch(splitSlice[1])
	if len(playnameTxt) == 0 {
		return "", "", ""
	}
	playerId := playnameTxt[1]
	//处理玩家名字
	reg2 := regexp.MustCompile(`(.*?)\(`)
	playerIdTxt := reg2.FindStringSubmatch(splitSlice[1])
	if len(playerIdTxt) == 0 {
		return "", "", ""
	}
	playerName := playerIdTxt[1]
	return playerName, playerId, playerStreamId
}

// 聊天类型，聊天内容
func (r *ChatRule) GetChatInfo(str string) (string, string) {
	reg := regexp.MustCompile(`'([^']*)'`)
	strslices := reg.FindAllStringSubmatch(str, -1)
	if len(strslices) == 0 {
		return "无类型", "无内容"
	}
	chatTxts := strslices[1]
	//冒号分割strings.Split(strslice[1], ":")
	splitSlice := strings.Split(chatTxts[1], ":")
	if len(splitSlice) < 2 {
		return "无类型", "无内容"
	}
	chatType := splitSlice[0]
	chatContent := splitSlice[1]
	return chatType, chatContent
}
